package ee.ut.maxorato_macobo.oop.mud.items;

import ee.ut.maxorato_macobo.oop.mud.game.PlayerCharacter;

public class ItemFood extends ItemBase {
	private ItemFoodTemplate itemTemplate;
	
	public ItemFood(ItemTemplate newItemTemplate, ContainsItems newItemLocation) {
		super(newItemTemplate, newItemLocation);
		
		itemTemplate = (ItemFoodTemplate)newItemTemplate;
	}
	
	public int getRestoreEnergy() {
		return itemTemplate.getRestoreEnergy();
	}
	
	public void consumedByPlayer(PlayerCharacter player) {
		int restoredEnergy = 0;
		
		if(player.getEnergy() < player.getMaxEnergy()) {
			restoredEnergy = Math.min(getRestoreEnergy(), player.getMaxEnergy() - player.getEnergy());
			player.setEnergy(player.getEnergy() + restoredEnergy);
		}
		
		player.sendTickMessage("You ate " + getName() + ", it restored " + restoredEnergy + " energy.");
		
		removeFromLocation();
	}
	
	@Override
	public ItemBase clone() {
		return new ItemFood(itemTemplate, itemLocation);
	}
}
